package com.smh;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

/**
 * @author shiminghui
 * @date 2024/12/15 14:42
 * @description: TODO
 */
public class test {
    /*    Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        int[] arr = new int[i];
            scanner.nextLine();
        String s = scanner.nextLine();
        String[] split = s.split(" ");
            if (split.length != i) {
            throw new RuntimeException();
        }
            for (int i1 = 0; i1 < i; i1++) {
            arr[i1] = Integer.parseInt(split[i1]);
        }

        int fun = fun2(arr);
            System.out.println(fun);*/
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
//        int i = scanner.nextInt();
//        int i1 = fun3(i);
//        System.out.println(i1);
//        int i = scanner.nextInt();
//        int i1 = scanner.nextInt();
//        scanner.nextLine();
        String s = scanner.nextLine();
//        System.out.println(i+""+i1+s);
//        int i2 = fun4(i, i1, s);
//        System.out.println(i2);
        int i = fun5(s);
        System.out.println(i);
    }

    public static int fun(int[] arr) {
        if (arr.length == 1) {
            return arr[0];
        } else if (arr.length == 2) {
            return Math.max(arr[0], arr[1]);
        }
        int flag = 0, index = 2;
        int a = arr[0], b = arr[1];
        while (a > 0 || b > 0) {
            int min = Math.min(a, b);
            if (min > 0) {
                a -= min;
                b -= min;
                flag += min;
            } else {
                int max = Math.max(a, b);
                a = 0;
                b = 0;
                flag += max;
            }
            // 解决让谁上
            if (a == 0 && index < arr.length) {

                a = arr[index];
                index++;
            }
            if (b == 0 && index < arr.length) {
                b = arr[index];
                index++;
            }
        }
        return flag;
    }

    public static int fun2(int[] arr) {
        if (arr.length == 1) {
            return arr[0];
        } else if (arr.length == 2) {
            return Math.max(arr[0], arr[1]);
        }
        Arrays.sort(arr);
        int a = 0, b = 0;
        for (int i = arr.length - 1; i >= 0; i--) {
            if (a > b) {
                b += arr[i];
            } else if (a < b) {
                a += arr[i];
            } else {
                a += arr[i];
            }
        }
        return Math.max(a, b);
    }

    public static int fun3(int n) {
        if (n % 2 == 1) { //奇数
            int ji_flag = 0;
            int ou_flag = 0;
            int ji = n / 2 + 1;
            int ou = n / 2;
            int sum = 1;
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) { //第奇数个
                    sum *= (ji - ji_flag);
                    ji_flag++;
                } else {
                    sum *= (ou - ou_flag);
                    ou_flag++;
                }
            }
            return sum;
        } else { // 偶数
            int ji_flag = 0;
            int ou_flag = 0;
            int ji = n / 2;
            int ou = n / 2;
            int sum = 1;
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) { //第奇数个
                    sum *= (ji - ji_flag);
                    ji_flag++;
                } else {
                    sum *= (ou - ou_flag);
                    ou_flag++;
                }
            }
            if (ou % 2 == 0) {
                return sum * 3;
            }

            return sum * 2;
        }
    }

    public static int fun4(int n, int k, String s) {
        if (n <= k) {
            return n;
        }
        HashMap<Character, Integer> map = new HashMap<>();
        int res = 0, length = 0;
        char[] charArray = s.toCharArray();

        char begin = 0;
        for (int j = 0; j < charArray.length; j++) {
            if (map.containsKey(charArray[j])) {
                map.put(charArray[j], map.get(charArray[j]) + 1);
            } else {
                map.put(charArray[j], 1);
            }
            if (map.size() > k) {
                length = j - begin;
                res = Math.max(res, length);
                Integer i = map.get(charArray[begin]);
                length -= i;
                map.remove(charArray[begin]);
                begin += i;
            }
        }
        if (res == 0) {
            res = n;
        }
        return res;
    }

    public static int fun5(String s) {
        char[] charArray = s.toCharArray();
        int[] arr = new int[s.length()];
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < charArray.length; i++) {
            for (int j = 0; j < charArray.length; j++) {
                if (i != j) {
                    arr[i] += Math.min((charArray[j] - charArray[i] + 26) % 26, (charArray[i] - charArray[j] + 26) % 26);
                }
            }

            if (arr[i] < min) {
                min = arr[i];
            }
        }
        return min;
    }
}
